package xw.qxypt.modules.baseinfo.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.Query;

import xw.qxypt.modules.baseinfo.dao.LhpAlertDao;
import xw.qxypt.modules.baseinfo.entity.LhpAlertEntity;
import xw.qxypt.modules.baseinfo.entity.LhpEquipmentEntity;
import xw.qxypt.modules.baseinfo.entity.LhpInstallationPointEntity;
import xw.qxypt.modules.baseinfo.service.LhpAlertService;
import xw.qxypt.modules.baseinfo.service.LhpInstallationPointService;


@Service("lhpAlertService")
public class LhpAlertServiceImpl extends ServiceImpl<LhpAlertDao, LhpAlertEntity> implements LhpAlertService {

    @Autowired
    private LhpInstallationPointService lhpInstallationPointService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String alertType= (String) params.get("alertType");
        String date=new SimpleDateFormat("yyyy-MM-dd").format(new Date())+ " 00:00:00";
        IPage<LhpAlertEntity> page = this.page(
                new Query<LhpAlertEntity>().getPage(params),
                new QueryWrapper<LhpAlertEntity>()
                        .eq(StringUtils.isNotBlank(alertType),"alert_type", alertType)
                        .ge(StringUtils.isNotBlank(date),"alert_time", date)
                        .orderByDesc("alert_time")
        );
        List<LhpAlertEntity> alertList=page.getRecords();
        List<LhpInstallationPointEntity> pointList=lhpInstallationPointService.list();
        for(LhpAlertEntity alertEntity:alertList){
            for(LhpInstallationPointEntity pointEntity:pointList){
                if(alertEntity.getPointId().equals(pointEntity.getId())){
                    alertEntity.setPointName(pointEntity.getPointName());
                }
            }
        }
        return new PageUtils(page);
    }

}
